#include<iostream>
// zdl:: 河道题目就是到哪元最短路径的应用题
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
using pii = pair<int, int>;
const int N = 1e3, inf = 0x3f3f3f3f;
// 迪杰斯塔拉算法的前置条件
vector<pii> edges[N];
int dist[N];
bool st[N];
int n, p, c;

int id[N];
int f(int o)
{
    // 要进行重复使用的全局变量清除
    memset(dist, 0x3f, sizeof dist);
    memset(st, 0, sizeof st);
    // 优化版本的帝杰斯达拉算法需要小根堆
    priority_queue<pii, vector<pii>, greater<pii>> heap;
    heap.emplace(0, o);
    dist[o] = 0;
    while (heap.size())
    {
        auto x = heap.top(); heap.pop();
        int w = x.first, v = x.second;
        if (st[v]) continue;
        st[v] = true;

        // zdl:: 接下来进行松弛操作
        for (auto& y : edges[v])
        {
            int a = y.first, b = y.second;
            if (dist[a] > dist[v] + b)
            {
                dist[a] = dist[v] + b;
                heap.emplace(dist[a], a);
            }
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if (dist[id[i]] == inf) return inf;
        sum += dist[id[i]];
    }

    return sum;
}
int main()
{
    cin >> n >> p >> c;
    for (int i = 1; i <= n; i++) 
    {
        cin >> id[i];
    }
    for (int i = 1; i <= c; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    int ret = inf;
    // 接下来使用帝杰斯达拉算法求值！
    for (int i = 1; i <= p; i++)
    {
        ret = min(ret, f(i));
    }

    cout << ret << endl;
    return 0;
}